package com.gozap.sort.algorithm.cycle;

import com.gozap.sort.algorithm.Sort;
import com.gozap.sort.data.SortData;

/**
 * 插入排序具体排序算法实现
 * 
 * @author yaoming
 * @date 2013-1-4 下午05:07:04
 * @since JDK1.6
 * @version 2.0.0
 */
public class InsertSort implements Sort {

	private SortData data;

	@Override
	public void sort() {
		int len = getSortData().length();
		for (int i = 0; i < len - 1; i++) {
			for (int j = i + 1; j < len; j++) {
				if (getSortData().compare(i, j)) {
					getSortData().swap(i, j);
				}
			}
		}
	}

	@Override
	public SortData getSortData() {
		return data;
	}

	@Override
	public void setSortData(SortData sortDataType) {
		data = sortDataType;
	}
}
